package com.justgame.project.service.just.controller;

import com.justgame.project.base.annotation.ProtectAccess;
import com.justgame.project.cloud.common.constant.Result;
import com.justgame.project.service.api.dto.JustGameCompanyDTO;
import com.justgame.project.cloud.common.entity.PageRequest;
import com.justgame.project.service.just.service.JustGameCompanyService;
import lombok.AllArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/just/game-company")
@AllArgsConstructor
public class JustGameCompanyController {

    private final JustGameCompanyService gameCompanyService;
    /**
     * 首页工作室推荐
     *
     * @return
     */
    @GetMapping("/index-list")
    public Result<?> getHomeGameCompany() {
        return Result.OK(gameCompanyService.selectIndexList());
    }

    @GetMapping("/list")
    public Result<?> getList(PageRequest pageRequest, JustGameCompanyDTO dto) {
        return Result.OK(gameCompanyService.getList(pageRequest, dto));
    }

    @PostMapping("/save")
    @RequiresRoles("admin")
    @ProtectAccess
    public Result<?> addGameType(@Valid @RequestBody JustGameCompanyDTO dto) {
        return Result.OK(gameCompanyService.save(dto));
    }

    @DeleteMapping("/delete")
    @RequiresRoles("admin")
    @ProtectAccess
    public Result<?> deleteGameType(@RequestBody JustGameCompanyDTO dto) {
        return Result.OK(gameCompanyService.Delete(dto));
    }

    @PostMapping("/updateById")
    @RequiresRoles("admin")
    @ProtectAccess
    public Result<?> updateById(@RequestBody JustGameCompanyDTO dto) {
        return Result.OK(gameCompanyService.updateById(dto));
    }

}
